﻿/// 底部
$(function () {
    var footerModel = function () {
        this.init();
    };
    footerModel.prototype = {
        // 初始化
        init: function () {
            this.paint();
            this.bindEvent();
        },

        // 加载页面
        paint: function () {
            var cacheproductcount = getLocalStorage(STORAGE_MANAGER.cacheproductcount);
            var goodscount = "<span style='display: none'></span>"
            if (cacheproductcount && parseInt(cacheproductcount) > 0) {
                goodscount = "<span id='totalProductCount'>" + cacheproductcount + "</span>"
            }
            var html = [];
            html.push("<li tip='0'><i class='iconfont icon-shouye'></i><br/>首页</li>");
            html.push("<li tip='1'><i class='iconfont icon-classification01'></i><br/>分类</li>");
            html.push("<li tip='2'><i class='iconfont icon-star01'></i><br/>星粉星币</li>");
            html.push("<li tip='3'><div class='ftgwc'>" + goodscount + "<i class='iconfont icon-gouwuche'></i><br/><b class='dbgwc'>购物车</b></div></li>");
            html.push("<li tip='4'><i class='iconfont icon-wode'></i><br/>我的</li>");
            $("#footer").html(html.join("")).show();
        },

        // 绑定事件
        bindEvent: function () {
            var pathname = window.location.pathname;

            var currenttip = 0;
            if (pathname.indexOf("index.html") > -1) {
                currenttip = 0;
            } else if (pathname.indexOf("classification.html") > -1) {
                currenttip = 1;
            } else if (pathname.indexOf("coinlist.html") > -1) {
                currenttip = 2;
            } else if (pathname.indexOf("shoppingcart.html") > -1) {
                currenttip = 3;
            } else if (pathname.indexOf("mylife.html") > -1) {
                currenttip = 4;
            }
            $("#footer li[tip=" + currenttip + "]").addClass("color-fff");


            $("#footer ").on("click", "li", function () {
            	var tip = $(this).attr("tip");
                var targetli = $(this);                
                var activeli = $('#footer li[class=color-fff]');
                if (activeli.attr("tip") == tip) {
                    return;
                }
//              activeli.removeClass("color-fff");
//              targetli.addClass("color-fff");
				//设置购物车中所有商品数量
				var cacheproductcount = getLocalStorage(STORAGE_MANAGER.cacheproductcount);
				$("#totalProductCount").html(cacheproductcount);
				var currentLoginuser = getLocalStorage(STORAGE_MANAGER.user);
                switch (tip) {
                    case "0":
                        redirect("../home/index.html");
                        break;
                    case "1":
                        redirect("../home/classification.html");
                        break;
                    case "2":
                        redirect("../coin/coinlist.html");
                        break;
                    case "3":
		                    if(null == currentLoginuser){
		                    	redirect("../account/login.html?backurl=shopcart|shoppingcart.html");
		                    }else{
	                        redirect("../shopcart/shoppingcart.html");
		                   	}
                        break;
                    case "4":
                        redirect("../mine/mylife.html");
                        break;
                    default:
                        break;
                }
            });
        }
    };

    if (AGENT_CLIENT.WEB) {
        var footerModel = new footerModel();
    }
});